package com.bjsxt.shopcenter.common.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;

import com.bjsxt.shopcenter.common.util.PageInfoUtil;
import com.bjsxt.shopcenter.common.util.VerifyCodeUtils;

/**
 * 所有controller的父类
 * @author FanXiaokang
 *
 */
public class BaseController
{
	/* 提示信息 */
	protected String info;

	@RequestMapping("/randImg")
	public String randImg(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "No-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		//生成随机数
		String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
		//存入会话session
		HttpSession session = request.getSession(true);
		session.setAttribute("rand", verifyCode);
		//生成图片
		int w =200, h = 80;
		VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		return null;
	}
	/**
	 * 从Request中封装分页信息
	 * 所有的列表页面都要分页
	 * @param request
	 * @return
	 */
	protected PageInfoUtil proccedPageInfo(HttpServletRequest request)
	{
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		try
		{
			String currentPage = request.getParameter("currentPage");
			String pageSize = request.getParameter("pageSize");
			pageInfoUtil.setCurrentPage(Integer.valueOf(currentPage));
			pageInfoUtil.setPageSize(Integer.valueOf(pageSize));
		} catch (Exception e)
		{
		}
		return pageInfoUtil;
	}
}
